package com.feng.gaoerfu.bean;

import android.os.Parcel;
import android.os.Parcelable;

import java.util.ArrayList;

/**
 * @time 2017/8/29 0029 14:44
 */

public class BallPersonData implements Parcelable {
    //添加
    public static final int ADD = 1;
    public static final int PERSON = 2;
    //姓名
    public String name;
    //头像
    public int drawable;
    //球杆颜色
    public int ballColor;
    //类型
    public int type;
    //是否被中
    public boolean isSelected;

    //球洞
    public ArrayList<TableData> mTableDatas;
    //总计杆数
    public int totalNum = 0;
    //总计推杆
    public int totalTuiNum = 0;

    public BallPersonData(String name, int drawable, int ballColor) {
        this.name = name;
        this.drawable = drawable;
        this.ballColor = ballColor;
    }

    public BallPersonData(String name, int drawable) {
        this.name = name;
        this.drawable = drawable;
    }

    public BallPersonData(String name) {
        this.name = name;
    }

    public BallPersonData(int type) {
        this.type = type;
    }

    public BallPersonData() {
    }

    public void refresh() {
        if (mTableDatas != null && mTableDatas.size() != 0) {
            for (int i = 0; i < mTableDatas.size(); i++) {
                TableData tableData = mTableDatas.get(i);
                totalNum += tableData.numOfGan;
                totalTuiNum += tableData.numOfTui;
            }
        }

    }

    @Override
    public String toString() {
        return "BallPersonData{" +
                "name='" + name + '\'' +
                ", drawable=" + drawable +
                ", ballColor=" + ballColor +
                ", type=" + type +
                ", isSelected=" + isSelected +
                '}';
    }

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeString(this.name);
        dest.writeInt(this.drawable);
        dest.writeInt(this.ballColor);
        dest.writeInt(this.type);
        dest.writeByte(this.isSelected ? (byte) 1 : (byte) 0);
    }

    protected BallPersonData(Parcel in) {
        this.name = in.readString();
        this.drawable = in.readInt();
        this.ballColor = in.readInt();
        this.type = in.readInt();
        this.isSelected = in.readByte() != 0;
    }

    public static final Parcelable.Creator<BallPersonData> CREATOR = new Parcelable.Creator<BallPersonData>() {
        @Override
        public BallPersonData createFromParcel(Parcel source) {
            return new BallPersonData(source);
        }

        @Override
        public BallPersonData[] newArray(int size) {
            return new BallPersonData[size];
        }
    };
}
